package com.github.jarvett.http;

import org.smartboot.http.server.HttpRequest;
import org.smartboot.http.server.HttpResponse;

import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.Map;

public class SmartHttpContext {

    //uri和反射方法对应map
    static final Map<String, Method> uriMethodMap = new LinkedHashMap<>();
    static final Map<Method, Object> methodObjectMap = new LinkedHashMap<>();

    static String staticDir = null;

    static String classDir = null;

    //当前线程的HttpRequest的Map
    private final static ThreadLocal<HttpRequest> reqTLMap = new InheritableThreadLocal<>();
    //当前线程的HttpResponse的Map
    private final static ThreadLocal<HttpResponse> resTLMap = new InheritableThreadLocal<>();

    static void reqSet(HttpRequest request){
        reqTLMap.set(request);
    }

    static void reqRemove(){
        reqTLMap.remove();
    }

    public static HttpRequest currentHttpRequest(){
        return reqTLMap.get();
    }

    static void resSet(HttpResponse request){
        resTLMap.set(request);
    }

    static void resRemove(){
        resTLMap.remove();
    }

    public static HttpResponse currentHttpResponse(){
        return resTLMap.get();
    }

    public static String getStaticDir() {
        return staticDir;
    }

    public static String getClassDir() {
        return classDir;
    }
}
